<!DOCTYPE html>
<html>

<head>
    <title>注册</title>
    <% include layout/lib.ejs %>
    <link rel="stylesheet" type="text/css" href="/css/login.css" />
</head>

<body>
    <div class="loginBg">

        <div class="regsiterBox">
            <div class="loginTitleBox">登录</div>
            <div class="regsiterContent">
                <div class="regsiterContentLeft">
                    <a href="/index"><div class="goHome">返回首页</div></a>
                </div>
                <div class="regsiterContentRight">

                    <div class="inputItem" style="margin-top:20px;">
                        <i class="fa fa-user-o fa-lg"></i>
                        <input type="text" name="username" placeholder="请输入登录帐号（必填）" />
                    </div>
                    <div class="inputItem">
                            <i class="fa fa-key fa-fw" style="font-size:16px;"></i>
                        <input type="password" name="password" placeholder="请输入登录密码（必填）" />
                    </div>
                   
                    <div class="loginSubmit" style="margin-top:15px;">
                        立即登录
                    </div>
                    <div class="registerLink" style="margin-top:12px;margin-bottom:8px;">
                        <a href="/register"><span>没有帐号？点击注册</span></a>
                    </div>
                    <div class="codeLogin" style="font-size:12px;color:#999;border:1px dashed #ccc;background:#f5f5f5;">
                            <!-- <img src="/image/ed-19.png" /> -->
                            扫码登录，正在建设...
                        </div>
                        <p style="text-align: center;margin-top:10px;">该功能正在开发，敬请期待</p>
                </div>
            </div>
        </div>
        
    </div>
</body>
<script>


    customStorage.deleteLocalStorageValueAll();

    $(document).keyup(function(event){
		if(event.keyCode ==13){
			$(".loginSubmit").click();
		}
	});	

    $(".loginSubmit").click(function(){

        var username = $("input[name=username]").val();
        var password = $("input[name=password]").val();

        if(str_trim(username).length <= 0){
            POP.warning("验证提示","用户帐号不能为空");
            return;
        }

        if(str_trim(password).length <= 0){
            POP.warning("验证提示","用户密码不能为空");
            return;
        }

        var params = {
            username : username,
            password : password
        }

        POP.startLoading();

        HTTP.post("/user/login",params,(rs)=>{

            POP.endLoading();
            POP.success("提示信息","恭喜您，登录成功");

            //存储到本地
            customStorage.setPersistenceValue("userId",rs.userid);
            customStorage.setPersistenceValue("userName",rs.username);
            customStorage.setPersistenceValue("nickName",rs.nickname);
            customStorage.setPersistenceValue("header",rs.header);

            setTimeout(()=>{
                location.href = "/index";
            },1000)
        })

    });
</script>
</html>